<extend name="Public/base"/>

<block name="style">
	<link rel="stylesheet" type="text/css" href="__STATIC__/plugins/bootstrap-fileupload/bootstrap-fileupload.css" />
</block>

<block name="body">
    
    <div class="row">
        <div class="col-md-12">
            
            <div class="tabbable tabbable-custom boxless">
                <form id="form" action="{:U()}" method="post" class="form-1">
                <script> var _file = []; _file['picture'] = [];</script>
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tab_1" data-toggle="tab">基 础</a></li>
                    <li><a href="#tab_2" data-toggle="tab">高 级</a></li>
                </ul>
                
                <div class="tab-content">
                    <div id="tab_1" class="tab-pane active">
                    
                        <div class="portlet box red">
                            <div class="portlet-title">
                                <div class="caption"><i class="fa fa-reorder"></i> {:isset($info['id'])?'编辑':'新增'}分类</div>
                                <div class="tools">
                                    <a href="javascript:;" class="collapse"></a>
                                    <a href="#portlet-config" data-toggle="modal" class="config"></a>
                                    <a href="javascript:;" class="reload"></a>
                                    <a href="javascript:;" class="remove"></a>
                                </div>
                            </div>
                            <div class="portlet-body form">
                                <!-- BEGIN FORM-->
                                
                                    <div class="form-body">
                                        <div class="form-group">
                                            <label>上级分类</label>
                                            <input type="text" class="form-control input-xlarge" disabled="disabled" value="{$category['title']|default='无'}">
                                        </div>
                                        <div class="form-group">
                                            <label>分类名称<span class="check-tips">（名称不能为空）</span></label>
                                            <input type="text" class="form-control input-xlarge" name="title" value="{$info.title|default=''}">
                                        </div>
                                        <div class="form-group">
                                            <label>分类标识<span class="check-tips">（英文字母）</span></label>
                                            <input type="text" class="form-control input-xlarge" name="name" value="{$info.name|default=''}">
                                        </div>
                                        <div class="form-group">
                                            <label>发布内容<span class="check-tips">（是否允许发布内容）</span></label>
                                            <div class="radio-list">
                                                <label class="radio-inline">
                                                    <input type="radio" name="allow_publish"  value="0"> 不允许
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" name="allow_publish"  value="1" > 仅允许后台
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" name="allow_publish"  value="2"> 允许前后台
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label>是否审核<span class="check-tips">（在该分类下发布的内容是否需要审核）</span></label>
                                            <div class="radio-list">
                                                <label class="radio-inline">
                                                    <input type="radio" name="check"  value="0" checked> 不需要
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" name="check"  value="1"> 需要
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label>绑定文档模型<span class="check-tips">（分类支持发布的文档模型）</span></label>
                                            <volist name=":get_document_model()" id="list">
                                                <label class="checkbox-inline">
                                                    <input type="checkbox" name="model[]" value="{$list.id}">{$list.title}
                                                </label>
                                            </volist>
                                        </div>
                                        <div class="form-group">
                                            <label>允许文档类型</label>
                                            <volist name=":C('DOCUMENT_MODEL_TYPE')" id="type">
                                                <label class="checkbox-inline">
                                                    <input type="checkbox" name="type[]" value="{$key}">{$type}
                                                </label>
                                            </volist>
                                        </div>
                                        
                                    </div>
                                    
                                    
                                    <div class="form-actions fluid ">
                                        <div class="col-md-offset-3 col-md-9">
                                            <input type="hidden" name="id" value="{$info.id|default=''}">
                                            <input type="hidden" name="pid" value="{:isset($category['id'])?$category['id']:$info['pid']}">
                                            <button type="submit" id="submit" class="btn green submit-btn ajax-post" target-form="form-1">确 定</button>
                                            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>                    
                                        </div>
                                    </div>
                                
                                <!-- END FORM--> 
                            </div>
                        </div>
                        
                    </div>
                    <div id="tab_2" class="tab-pane">
                    
                        <div class="portlet box red">
                            <div class="portlet-title">
                                <div class="caption"><i class="fa fa-reorder"></i> {:isset($info['id'])?'编辑':'新增'}分类</div>
                                <div class="tools">
                                    <a href="javascript:;" class="collapse"></a>
                                    <a href="#portlet-config" data-toggle="modal" class="config"></a>
                                    <a href="javascript:;" class="reload"></a>
                                    <a href="javascript:;" class="remove"></a>
                                </div>
                            </div>
                            <div class="portlet-body form">
                                <!-- BEGIN FORM-->
                                
                                    <div class="form-body">
                                   		<div class="form-group">
                                            <label>分类图标</label>
                                            <script> _file['picture'].push("icon")</script>
                                            <div class="fileupload fileupload-new" data-provides="fileupload">
                                                <div class="fileupload-new thumbnail" >
                                                <empty name="info.icon">
                                                    <img id="field_pic_icon" src="__STATIC__/img/noimage.gif" alt="" />
                                                <else />
                                                    <img id="field_pic_icon" src="__ROOT__{$info.icon|get_cover='path'}" alt="" />
                                                </empty>
                                                </div>
                                                <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
                                                <div>
                                                    <input type="file" class="default"   id="icon"  />
                                                    <input type="hidden" name="icon" id="field_icon" value="{$info['icon']|default=''}"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label>可见性<span class="check-tips">（是否对用户可见，针对前台）</span></label>
                                            <select class="form-control input-medium" name="display">
                                                <option value="1">所有人可见</option>
                                                <option value="0">不可见</option>
                                                <option value="2">管理员可见</option>
                                            </select>
                                        </div>
                                    
                                        <div class="form-group">
                                            <label>回复<span class="check-tips">（是否允许对内容进行回复，需要详情页模板支持回复显示与提交）</span></label>
                                            <div class="radio-list">
                                                <label class="radio-inline">
                                                    <input type="radio" name="reply" value="1" checked>允许
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" name="reply" value="0">不允许
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label>排序<span class="check-tips">（仅对当前层级分类有效）</span></label>
                                            <input type="text" class="form-control input-xlarge" name="sort" value="{$info.sort|default=0}">
                                        </div>
                                        <div class="form-group">
                                            <label>列表行数</label>
                                            <input type="text" class="form-control input-xlarge" name="list_row" value="{$info.list_row|default=10}">
                                        </div>
                                        <div class="form-group">
                                            <label>网页标题</label>
                                            <input type="text" class="form-control input-xlarge" name="meta_title" value="{$info.meta_title|default=''}">
                                        </div>
                                        <div class="form-group">
                                            <label>关键字</label>
                                            <textarea class="form-control input-xlarge" rows="3"  name="keywords" >{$info.keywords|default=''}</textarea>
                                        </div>
                                    
                                        <div class="form-group">
                                            <label>描述</label>
                                            <textarea class="form-control input-xlarge" rows="3"  name="description" >{$info.description|default=''}</textarea>
                                        </div>
                                        <div class="form-group">
                                            <label>频道模板</label>
                                            <input type="text" class="form-control input-xlarge" name="template_index" value="{$info.template_index|default=''}">
                                        </div>
                                        <div class="form-group">
                                            <label>列表模板</label>
                                            <input type="text" class="form-control input-xlarge" name="template_lists" value="{$info.template_lists|default=''}">
                                        </div>
                                        <div class="form-group">
                                            <label>详情模板</label>
                                            <input type="text" class="form-control input-xlarge" name="template_detail" value="{$info.template_detail|default=''}">
                                        </div>
                                        <div class="form-group">
                                            <label>编辑模板</label>
                                            <input type="text" class="form-control input-xlarge" name="template_edit" value="{$info.template_edit|default=''}">
                                        </div>
                                    </div>
                                    
                                    
                                    <div class="form-actions fluid ">
                                        <div class="col-md-offset-3 col-md-9">
                                            <input type="hidden" name="id" value="{$info.id|default=''}">
                                            <input type="hidden" name="pid" value="{:isset($category['id'])?$category['id']:$info['pid']}">
                                            <button type="submit" id="submit" class="btn green submit-btn ajax-post" target-form="form-1">确 定</button>
                                            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>                    
                                        </div>
                                    </div>
                                
                                <!-- END FORM--> 
                            </div>
                        </div>
                        
                    </div>
                </div>
                
                </form>
            </div>
        </div>
    </div>
</block>

<block name="script">
	<script type="text/javascript">
		$(function(){
			<present name="info.id">
			setValue("allow_publish", {$info.allow_publish|default=1});
			setValue("check", {$info.check|default=0});
			setValue("model[]", {$info.model|json_encode} || [1]);
			setValue("type[]", {$info.type|json_encode} || [2]);
			setValue("display", {$info.display|default=1});
			setValue("reply", {$info.reply|default=0});
			setValue("reply_model[]", {$info.reply_model|json_encode} || [1]);
			</present>
			
		})
	</script>
    
    <!-- BEGIN PAGE LEVEL PLUGINS -->
	<script type="text/javascript" src="__STATIC__/plugins/bootstrap-fileupload/bootstrap-fileupload.js"></script>
	<!-- END PAGE LEVEL PLUGINS -->
	<!-- BEGIN PAGE LEVEL SCRIPTS -->
	<script src="__STATIC__/scripts/app.js"></script>
	<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
	<!-- END PAGE LEVEL SCRIPTS -->
	<script>
	jQuery(document).ready(function() {       
		// initiate layout and plugins
		App.init();

        highlight_subnav('{:U('Category/index')}');
		
		_file['picture'].forEach(function(i){
			$("#"+i).uploadify({
				"height"          : 34,
				"swf"             : "__STATIC__/uploadify/uploadify.swf",
				"fileObjName"     : "download",
				"buttonText"      : "上传图片",
				"uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
				"width"           : 80,
				'removeTimeout'	  : 1,
				'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
				"onUploadSuccess" : function(file, data){
					var data = $.parseJSON(data);
					var src = '';
					if(data.status){
						$("#field_"+i).val(data.id);
						src = data.url || '__ROOT__' + data.path
						$("#field_pic_"+i).attr({"src":src}).parent().css({"width":'',"height":''});
					} else {
						updateAlert(data.info);
						setTimeout(function(){
							$('#top-alert').find('button').click();
							$(that).removeClass('disabled').prop('disabled',false);
						},1500);
					}
				},
				'onFallback' : function() {
					alert('未检测到兼容版本的Flash.');
				}
			});
		})
		
	});
	</script>
</block>
